<?php
error_reporting(E_ALL | E_STRICT);

function __autoload($class_name)
{
	require '_class/'.str_replace('_', '/', $class_name).'.php';
}
ini_set('xdebug.var_display_max_depth', -1);
ini_set('xdebug.var_display_max_data', -1);


SF_Config::removeMagicQuotes();

class U1_Account_Register extends SF_GenerateCode_Form
{
	public function init()
	{
		$this->method = 'get';
		$this->action = SF_Form::DEFAULT_ACTION;
		$this->addElement(new SF_Form_Element_Text('login', array(
			'validators'=> array(
				new SF_Validate_StringLength(3, 25)
			)
		)))
		->addElement(new SF_Form_Element_Text('pseudo', array(
			'validators'=> array(
				new SF_Validate_StringLength(5, 20)
			)
		)))
		->addElement(new SF_Form_Element_Password('password', array(
			'validators'=> array(
				new SF_Validate_StringLength(8)
			)
		)))
		->addElement(new SF_Form_Element_Password('confirm', array(
			'validators'=> array(
				new SF_Validate_EqualValue($this->elements['password'], 'getValue')
			)
		)))
		->addElement(new SF_Form_Element_Text('mail', array(
			'validators'=> array(
				new SF_Validate_StringLength(0, 50),
				new SF_Validate_Email()
			)
		)))
		->addElement(new SF_Form_Element_Select('race', array(
			'enum' => array('ashen', 'eldarks', 'yukron', 'werlingz')
		)))
		->addElement(new SF_Form_Element_Boolean('settlement'));
	}

	/**
	 * @param string|SF_View_Form $view = NULL : nom ou objet SF_View_Form. Si NULL un objet SF_View_Form est créé
	 * @return SF_View_Form
	 *
	 * @exception SF_Form_Exception : La vue doit être du type SF_View_Form
	 */
	public function getView($view = NULL)
	{
		$view = $this->getViewForm($view);
		$this->elements['race']->setListDrop(false);

		$view->addGroup('Information privée', array(
			$this->getViewElement('login')		->addLabel('Identifiant'),
			$this->getViewElement('password')	->addLabel('Mot de passe'),
			$this->getViewElement('confirm')	->addLabel('Répétez le mot de passe'),
			$this->getViewElement('mail')		->addLabel('Adresse e-mail')
		))
		->addGroup('Information public', array(
			$this->getViewElement('pseudo')		->addLabel('pseudo'),
			$this->getViewElement('race')		->addLabel('Clan')
				->addLabelOption('yukron', 'Yukron')
				->addLabelOption('eldarks', 'Eldarks')
				->addLabelOption('ashen', 'Ashen')
				->addLabelOption('werlingz', 'Werlingz')
		))
		->addGroup('Réglement', array(
			$this->getViewElement('settlement')	->addLabel('J\'ai lu et j\'accepte les règles.', 'after')
		))
		->addError(SF_View_Decorator::factory('ul')->wrapContentTag('li')->wrapTag('div', array('style'=>'border:1px solid red;background-color:#aff')));

		foreach ($view->getElements() as $element)
		{
			$element->wrapTag('div')
			->addError(new SF_View_Decorator('div', array('style'=>'border:1px solid red;background-color:#c99')));
		}

		return $view->addElement(
			$this->submit->getView()
		);
	}
}

header('Content-Type: text/html; charset=utf-8');
$form = new U1_Account_Register();
if ($form->setSubmit('valider')->isSubmit())
	var_dump($form->isValid(), $form->getMessages());
$render = $form->getView()->render();
echo '<pre>';
highlight_string($render);